#include <iostream>
#include <cstring>

using namespace std;

const int N = 210;
int dp1[N][N], dp2[N][N];
int a[N], f[N];
int n;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i + n] = a[i];
		
	}
	int m = n + n;
	for(int i = 1; i <= m; i++)
	{
		f[i] = f[i - 1] + a[i];
	}
	memset(dp1, 0x3f, sizeof dp1);
	memset(dp2, -0x3f, sizeof dp2);
	for(int i = 1; i <= m; i++)
	{
		dp1[i][i] = dp2[i][i] = 0;
	}
	for(int len = 2; len <= n; len++)
	{
		for(int i = 1; i + len - 1 <= m; i++)
		{
			int j = i + len - 1;
			int t = f[j] - f[i - 1];
			for(int k = i; k < j; k++)
			{
				dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k + 1][j] + t);
				dp2[i][j] = max(dp2[i][j], dp2[i][k] + dp2[k + 1][j] + t);
			}
		}
	}
	int ret1 = 0x3f3f3f3f, ret2 = -0x3f3f3f3f;
	for(int i = 1; i <= n; i++)
	{
		ret1 = min(ret1, dp1[i][n + i - 1]);
		ret2 = max(ret2, dp2[i][n + i - 1]);
	}
	cout << ret1 << endl << ret2 << endl;
	return 0;
}
